home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C / Applications / Moscow ML 1.42 / lib / Date.sig < prev    next >
Encoding:
Text File  |  1997-08-18  |  4.1 KB  |  95 lines  |  [TEXT/Moml]

  1. (* Date -- SML Basis Library *)
  2.  
  3. datatype weekday = Mon | Tue | Wed | Thu | Fri | Sat | Sun
  4.  
  5. datatype month = Jan | Feb | Mar | Apr | May | Jun
  6.                | Jul | Aug | Sep | Oct | Nov | Dec
  7.  
  8. datatype date = DATE of {
  9.     year   : int,                       (* e.g. 1995 *)
  10.     month  : month,
  11.     day    : int,                       (* 1-31  *)
  12.     hour   : int,                       (* 0-23  *)
  13.     minute : int,                       (* 0-59  *)
  14.     second : int,                       (* 0-61 (allowing for leap seconds) *)
  15.     wday   : weekday option,
  16.     yday   : int option,                (* 0-365 *)
  17.     isDst  : bool option                (* daylight savings time in force *)
  18.   }
  19.  
  20. exception Date
  21.  
  22. val fromTime : Time.time -> date
  23. val fromUTC  : Time.time -> date
  24. val toTime   : date -> Time.time
  25.  
  26. val compare  : date * date -> order
  27.  
  28. val toString   : date -> string
  29. val fmt        : string -> date -> string
  30. val fromString : string -> date option
  31. val scan       : (char, 'a) StringCvt.reader -> (date, 'a) StringCvt.reader
  32.  
  33. (* These functions convert times to dates and vice versa, and format
  34.    and scan dates.
  35.  
  36.    [fromTime t] returns the local date at time t.  The fields year,
  37.    month, day, hour, minute, and second are as expected.  The fields
  38.    wday and yday are guaranteed to be SOME _, whereas isDst may be
  39.    NONE if the system cannot determine whether daylight savings time
  40.    is in effect at the given time.  Corresponds to the ANSI C function 
  41.    `localtime'.
  42.  
  43.    [fromUTC t] is similar to fromTime, but returns the UTC date at
  44.    time t.  Corresponds to the ANSI C function `gmtime'.
  45.  
  46.    [toTime dt] returns the time corresponding to the local date dt.
  47.    Ignores the yday and wday fields (it does not matter whether they
  48.    are NONE or SOME _).  Uses the isDst time field if it is present
  49.    (SOME _) and cannot be calculated from the given date.  May raise
  50.    Date if the given date is invalid.  Raises Time.Time if the Date
  51.    cannot be represented as a Time.time value.  At least the dates in
  52.    the interval 1970-2030 can be represented as Time.time values.  
  53.    Corresponds to the ANSI C function `mktime'.
  54.  
  55.    The weekday wday of a given date dt can be found by evaluating:
  56.        val DATE {wday = SOME wday, ...} = fromTime(toTime dt) 
  57.    The yday and isDst can be computed similarly.
  58.  
  59.    [compare(d1, d2)] returns LESS, EQUAL, or GREATER, according 
  60.    as date d1 precedes, equals, or follows d2 in time.  Lexicographically
  61.    compares the dates, ignoring wday, yday, and isDst, and does not detect
  62.    invalid dates.
  63.  
  64.    [toString dt] returns a 24 character string representing the date dt
  65.    in the following format:  
  66.               Wed Mar  8 19:06:45 1995
  67.    It ignores the weekday (if supplied) and recomputes it on the basis of 
  68.    the other fields; the result may be wrong if the date is outside the
  69.    representable Time.time range.  Raises Date if the given date is invalid.
  70.    Corresponds to the ANSI C function `asctime'.
  71.  
  72.    [fmt fmtstr dt] formats the date dt according to the format string
  73.    fmtstr.  The format string has the same meaning as with the ANSI C
  74.    function `strftime'.  For instance, (fmt "%A" dt) returns the full
  75.    name of the weekday, such as "Monday", for the given date.  For a
  76.    full description of the fmt syntax, consult a description of
  77.    strftime.  Ignores the weekday field (if supplied) and recomputes
  78.    it on the basis of the other fields; the result may be wrong if the
  79.    date is outside the representable Time.time range.  Raises Date if
  80.    the given date is invalid.
  81.  
  82.    [fromString s] scans a 24-character date from the string s, after
  83.    possible initial whitespace (blanks, tabs, newlines).  The format
  84.    of the string must be as produced by toString.  The fields yday and
  85.    isDst in the resulting date will be NONE.  No check of the
  86.    consistency of the date (weekday, date in the month, ...) is
  87.    performed.
  88.  
  89.    [scan getc src] scans a 24-character date from the stream src,
  90.    using the stream accessor getc.  Otherwise works as fromString.  In
  91.    case of success, returns SOME(date, rst) where date is the scanned
  92.    date and rst is the remainder of the stream; otherwise returns
  93.    NONE.
  94. *)
  95.